<%--
  Created by IntelliJ IDEA.
  User: LENOVO
  Date: 2023/9/21
  Time: 16:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>邮箱验证码</title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
            background-color: #f2f2f2;
        }
        .container {
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
        .form-group {
            margin-bottom: 20px;
        }
        label, input[type="email"], input[type="code"], input[type="submit"] {
            display: block;
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
        }
        input[type="submit"] {
            background-color: #4CAF50;
            color: #fff;
            cursor: pointer;
        }
        a {
            text-decoration: none;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>根据邮箱找回密码</h1>
    <p style="color: red;" id="msg"></p>
    <form id="forgotPasswordForm" action="upda.jsp" method="post">
        <div>邮箱：
            <input type="email" id="to" name="to" required placeholder="请输入邮箱"/>
            <input type="button" name="send" value="发送邮件" onclick="sendCode()"  />
        </div>
        <div>验证码：
        <input type="code" id="code" name="code" onblur="checkCode()" required placeholder="请输入验证码"/>
            <span id="msgCode"></span>
        </div>
        <br>
        <div class="form-group">
            <input type="submit" value="确定">
        </div>
        <div class="form-group">
            <a href="phone.jsp">切换为手机号验证</a>
        </div>
    </form>
</div>
</body>
<script src="js/jquery.js"></script>
<script>
    function sendCode() {
        $("[name=send]").attr("disable");
        $.post("SendServlet","to="+$("#to").val(),function (data) {
            if(data=="true"){
                alert("邮件已发送")
            }else {
                alert("邮件发送失败")
            }
        },"text")
    }
    //检查验证码
    function checkCode() {
        var userCode=$("#code").val();
        $.post("CheckCodeServlet","code="+userCode,function (data) {
            if(data=="true"){
                $("#msgCode").html("✔")
                return true;
            }else {
                $("#msgCode").html("✘")
                return false;
            }
        },"text")
    }
</script>
</html>